<template>
    <div class="demo">
        <h2 >学校名称:{{name}}</h2>
        <h2>学校地址:{{address}}</h2>
    </div>
</template>
<script>
import pubsub from 'pubsub-js'
export default {
    name: 'StuSchool',
    data () {
        return {
            name: 'wqewqe',
            address: 'zxcxzcx',
            pubId: ''
        }
    },
    methods: {
        demo (msgName, data) {
            console.log('有人发布了hello消息,hello消息的回调执行了:'+data)
        }
    },
    mounted () {
    //    this.pubId = pubsub.subscribe('hello', function(msgName, data){
    //         console.log('有人发布了hello消息,hello消息的回调执行了:'+data)
    //     })
    this.pubId = pubsub.subscribe('hello', this.demo)
    },
    beforeDestroy () {
        pubsub.unsubscribe(this.pubId)
    }
}
</script>
<style lang="less" scoped>
    .demo {
        background-color: orange;
        padding: 5px;
        h2 {
            color: red;
        }
    }
</style>